package com.codding.springboot_mybatisdemo.service.Impl;

import com.codding.springboot_mybatisdemo.entity.Admin;
import com.codding.springboot_mybatisdemo.mapper.AdminMapper;
import com.codding.springboot_mybatisdemo.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private AdminMapper adminMapper;

    //处理业务逻辑
    @Override
    public Admin login(Admin admin) {
        if (admin.getAdminName() == null || admin.getAdminPassword() == null) {
            return null;
        } else {
            Admin login = adminMapper.login(admin);
            return login;
        }
    }

    @Override
    public int register(String username, String password, String confirmPassword, boolean check) {
        if (!check){
            return 2;
        }

        if (!password.equals(confirmPassword)){
            return 3;
        }

        Admin admin = adminMapper.selectByName(username);
        if (admin != null){
            return 4;
        }
        Admin admin1 = new Admin();
        admin1.setAdminName(username);
        admin1.setAdminPassword(password);
        Integer register = adminMapper.register(admin1);
        return register;
    }
}
